package com.zj.config;


import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;

/**
 * 专门用来解决文件上传时的问题
 * 指定feign文件上传的协议
 */
public class FeignMultipartSupportConfig {

    private final ObjectFactory<HttpMessageConverters> messageConverters; //消息转换器

    public FeignMultipartSupportConfig(ObjectFactory<HttpMessageConverters>messageConverters){
        this.messageConverters=messageConverters;
    }

    //feign表单编码器
    @Bean
    public Encoder feignFormEncoder(){
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }
}
